<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}小红书数据管理系统{% endblock %}</title>
    <!-- 引入字体 -->
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;700&display=swap" rel="stylesheet">
    <!-- 引入Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 引入Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
    <!-- 引入Animate.css -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">

    <link rel="stylesheet" href="https://at.alicdn.com/t/c/font_4930117_l66rjrhgmxk.css">

    <style>
        :root {
            --primary-color: #FF4F5E;
            --primary-dark: #E93E4D;
            --secondary-color: #6A7BFF;
            --dark-color: #343a40;
            --light-color: #f8f9fa;
            --success-color: #2DCE89;
            --info-color: #11CDEF;
            --warning-color: #FB6340;
            --danger-color: #F5365C;
        }

        body {
            font-family: 'Nunito', sans-serif;
            background-color: #f9fafb;
            padding-top: 60px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 顶部导航栏 */
        .navbar {
            background-color: #fff;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            padding: 0.5rem 1rem;
        }

        .navbar-brand {
            font-weight: 700;
            color: var(--primary-color);
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            font-size: 1.5rem;
            margin-right: 0.5rem;
        }

        /* 侧边栏 */
        .sidebar {
            position: fixed;
            top: 60px;
            bottom: 0;
            left: 0;
            width: 250px;
            z-index: 100;
            padding: 0;
            box-shadow: 0 0.15rem 1.75rem rgba(0, 0, 0, 0.05);
            background: #fff;
            transition: all 0.3s ease;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
        }
        
        .sidebar-footer {
            margin-top: auto;
            padding: 1rem;
            border-top: 1px solid rgba(0, 0, 0, 0.05);
            text-align: right;
        }
        
        .sidebar-footer #sidebar-toggle {
            background-color: var(--primary-color);
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            transition: all 0.3s;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.1);
        }
        
        .sidebar-footer #sidebar-toggle:hover {
            background-color: var(--primary-dark);
            transform: scale(1.05);
        }
        
        .sidebar-collapsed .sidebar-footer #sidebar-toggle i {
            transform: rotate(180deg);
        }

        .sidebar-header {
            padding: 1.5rem 1rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        }

        .sidebar-user {
            display: flex;
            align-items: center;
        }

        .sidebar-user-img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 10px;
            background-color: var(--primary-color);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
        }

        .sidebar-user-info {
            font-size: 0.9rem;
        }

        .sidebar-user-name {
            font-weight: 600;
            margin-bottom: 0;
        }

        .sidebar-user-role {
            color: #6c757d;
            font-size: 0.8rem;
        }

        .sidebar .nav-link {
            padding: 0.75rem 1.25rem;
            color: #6e7079;
            font-weight: 600;
            display: flex;
            align-items: center;
            border-radius: 0.375rem;
            margin: 0.2rem 0.7rem;
            transition: all 0.3s;
        }

        .sidebar .nav-link:hover {
            color: var(--primary-color);
            background-color: rgba(255, 79, 94, 0.1);
        }

        .sidebar .nav-link.active {
            color: var(--primary-color);
            background-color: rgba(255, 79, 94, 0.1);
        }

        .sidebar .nav-link i {
            margin-right: 0.5rem;
            width: 20px;
            text-align: center;
            font-size: 1rem;
        }

        .sidebar .nav-heading {
            padding: 1.25rem 1.25rem 0.5rem;
            font-size: 0.7rem;
            text-transform: uppercase;
            letter-spacing: 0.05rem;
            color: #abb0bb;
            font-weight: 700;
        }

        /* 主内容区 */
        .main-content {
            margin-left: 250px;
            padding: 1.5rem;
            flex: 1;
            transition: margin-left 0.3s ease;
        }

        /* 页面标题区 */
        .page-header {
            margin-bottom: 1.5rem;
        }

        .page-title {
            font-weight: 700;
            color: #344767;
            margin-bottom: 0.5rem;
        }

        /* 卡片样式 */
        .card {
            border: none;
            border-radius: 0.75rem;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            transition: transform 0.3s, box-shadow 0.3s;
            margin-bottom: 1.5rem;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
        }

        .card-header {
            background-color: transparent;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            padding: 1rem 1.25rem;
            font-weight: 600;
        }

        /* 数据卡片样式 */
        .stat-card {
            border-radius: 0.75rem;
            overflow: hidden;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
        }

        .stat-card .card-body {
            padding: 1.25rem;
        }

        .stat-card .icon-box {
            width: 48px;
            height: 48px;
            border-radius: 0.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            color: #fff;
        }

        .stat-card .stat-title {
            font-size: 0.875rem;
            color: #8898aa;
            font-weight: 600;
            margin-bottom: 0.5rem;
        }

        .stat-card .stat-value {
            font-size: 1.5rem;
            font-weight: 700;
            color: #344767;
            margin-bottom: 0;
        }

        .stat-card .stat-change {
            font-size: 0.75rem;
            font-weight: 600;
        }

        /* 按钮样式 */
        .btn-primary {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }

        .btn-primary:hover, .btn-primary:focus {
            background-color: var(--primary-dark);
            border-color: var(--primary-dark);
        }

        .btn-outline-primary {
            color: var(--primary-color);
            border-color: var(--primary-color);
        }

        .btn-outline-primary:hover {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }

        /* 表格样式 */
        .table {
            color: #525f7f;
            border-color: #e9ecef;
        }

        .table thead th {
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.025rem;
            color: #8898aa;
            font-weight: 700;
            border-bottom-width: 1px;
            padding-top: 0.75rem;
            padding-bottom: 0.75rem;
        }

        .table td {
            vertical-align: middle;
            padding: 0.75rem 1rem;
            font-size: 0.875rem;
        }

        /* 页脚 */
        footer {
            background-color: #fff;
            padding: 1rem 0;
            margin-top: auto;
            margin-left: 250px;
            transition: margin-left 0.3s ease;
            border-top: 1px solid rgba(0, 0, 0, 0.05);
            font-size: 0.875rem;
            color: #6c757d;
        }

        /* 自适应布局 */
        @media (max-width: 991.98px) {
            .sidebar {
                transform: translateX(-100%);
            }
            .sidebar.show {
                transform: translateX(0);
            }
            .main-content, footer {
                margin-left: 0;
            }
        }

        /* 侧边栏折叠 */
        .sidebar-collapsed .sidebar {
            width: 70px;
        }
        
        .sidebar-collapsed .sidebar .nav-text,
        .sidebar-collapsed .sidebar .sidebar-user-info,
        .sidebar-collapsed .sidebar .nav-heading {
            display: none;
        }
        
        .sidebar-collapsed .sidebar .nav-link {
            justify-content: center;
            padding: 0.75rem;
        }
        
        .sidebar-collapsed .sidebar .nav-link i {
            margin-right: 0;
        }
        
        .sidebar-collapsed .sidebar-footer {
            text-align: center;
            padding: 0.5rem;
        }
        
        .sidebar-collapsed .main-content,
        .sidebar-collapsed footer {
            margin-left: 70px;
        }

        /* 消息提示 */
        .toast-container {
            position: fixed;
            top: 70px;
            right: 20px;
            z-index: 1090;
        }

        /* 加载动画 */
        .loader {
            width: 100%;
            height: 4px;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1100;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            animation: loading 2s infinite;
        }

        @keyframes loading {
            0% {
                transform: translateX(-100%);
            }
            100% {
                transform: translateX(100%);
            }
        }

        /* 其他辅助样式 */
        .badge {
            padding: 0.35em 0.65em;
            font-weight: 600;
            border-radius: 0.375rem;
        }

        .badge-primary {
            background-color: var(--primary-color);
        }

        .text-primary {
            color: var(--primary-color) !important;
        }

        .bg-primary {
            background-color: var(--primary-color) !important;
        }

        .bg-success {
            background-color: var(--success-color) !important;
        }

        .bg-info {
            background-color: var(--info-color) !important;
        }

        .bg-warning {
            background-color: var(--warning-color) !important;
        }

        .chart-container {
            height: 350px;
            width: 100%;
        }
    </style>
    {% block styles %}{% endblock %}
</head>
<body>
    <!-- 页面加载动画 -->
    <div class="loader" id="page-loader"></div>

    <!-- 顶部导航栏 -->
    <nav class="navbar navbar-expand-lg fixed-top navbar-light">
        <div class="container-fluid">
            <button class="btn btn-link sidebar-toggle d-lg-none me-2" id="mobile-toggle">
                <i class="fas fa-bars"></i>
            </button>
            <a class="navbar-brand" href="/">
                <i class="fas fa-fire text-primary"></i>
                <span>汇友数据管理</span>
            </a>
            <div class="navbar-nav ms-auto d-flex align-items-center">
                <div class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <i class="fas fa-bell"></i>
                        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                            3
                        </span>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                        <li><h6 class="dropdown-header">通知中心</h6></li>
                        <li><a class="dropdown-item" href="#"><i class="fas fa-tasks me-2 text-primary"></i>任务完成: 关键词采集</a></li>
                        <li><a class="dropdown-item" href="#"><i class="fas fa-exclamation-circle me-2 text-warning"></i>系统提醒: 需要更新</a></li>
                        <li><a class="dropdown-item" href="#"><i class="fas fa-chart-line me-2 text-success"></i>数据报告已生成</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item text-center" href="#">查看所有通知</a></li>
                    </ul>
                </div>
                <div class="nav-item dropdown ms-2">
                    <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <div class="avatar-circle me-2" style="width: 32px; height: 32px; background-color: var(--primary-color); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white;">
                            {% if session.username %}
                                {{ session.username[0] | upper }}
                            {% else %}
                                <i class="fas fa-user"></i>
                            {% endif %}
                        </div>
                        <span>
                            {% if session.username %}
                                {{ session.username }}
                            {% else %}
                                访客
                            {% endif %}
                        </span>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                        {% if session.user_id %}
                            <li><a class="dropdown-item" href="#"><i class="fas fa-user me-2"></i>个人资料</a></li>
                            {% if session.user_role == 0 %}
                                <li><a class="dropdown-item" href="#"><i class="fas fa-users-cog me-2"></i>用户管理</a></li>
                            {% endif %}
                            <li><a class="dropdown-item" href="#"><i class="fas fa-cog me-2"></i>账号设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('xhs.logout') }}"><i class="fas fa-sign-out-alt me-2"></i>退出登录</a></li>
                        {% else %}
                            <li><a class="dropdown-item" href="{{ url_for('xhs.login') }}"><i class="fas fa-sign-in-alt me-2"></i>登录</a></li>
                        {% endif %}
                    </ul>
                </div>
            </div>
        </div>
    </nav>

    <!-- 侧边栏 -->
    <nav class="sidebar">
        <div class="sidebar-header">
            <div class="sidebar-user">
                <div class="sidebar-user-img">
                    {% if session.username %}
                        {{ session.username[0] | upper }}
                    {% else %}
                        <i class="fas fa-user"></i>
                    {% endif %}
                </div>
                <div class="sidebar-user-info">
                    <div class="sidebar-user-name">
                        {% if session.real_name %}
                            {{ session.real_name }}
                        {% else %}
                            游客
                        {% endif %}
                    </div>
                    <div class="sidebar-user-role">
                        {% if session.user_role == 0 %}
                            管理员
                        {% elif session.user_role == 1 %}
                            普通用户
                        {% else %}
                            未登录
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
        <ul class="nav flex-column">
            <li class="nav-heading">主要功能</li>
            <li class="nav-item">
                <a class="nav-link {% if request.path == '/' %}active{% endif %}" href="/">
                    <i class="fas fa-tachometer-alt"></i>
                    <span class="nav-text">仪表盘</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if '/notes' in request.path and '/notes/' not in request.path %}active{% endif %}" href="/notes">
                    <i class="fas fa-book-open"></i>
                    <span class="nav-text">笔记管理</span>
                </a>
            </li>
         
            <li class="nav-item">
                <a class="nav-link {% if '/crawler' in request.path %}active{% endif %}" href="/crawler">
                    <i class="fas fa-spider"></i>
                    <span class="nav-text">爬虫工具</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if '/locations' in request.path %}active{% endif %}" href="/locations">
                    <i class="fas fa-map-marker-alt"></i>
                    <span class="nav-text">位置分析</span>
                </a>
            </li>
            <li class="nav-heading">数据分析</li>
            <li class="nav-item">
                <a class="nav-link {% if '/statistics' in request.path %}active{% endif %}" href="/statistics">
                    <i class="fas fa-chart-bar"></i>
                    <span class="nav-text">数据统计</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if '/data-screen' in request.path %}active{% endif %}" href="/data-screen">
                    <i class="fas fa-desktop"></i>
                    <span class="nav-text">数据大屏</span>
                </a>
            </li>
            <li class="nav-heading">数据管理</li>
            <li class="nav-item">
                <a class="nav-link {% if '/export' in request.path %}active{% endif %}" href="/export">
                    <i class="fas fa-file-export"></i>
                    <span class="nav-text">数据导出</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if '/import' in request.path %}active{% endif %}" href="/import">
                    <i class="fas fa-file-import"></i>
                    <span class="nav-text">数据导入</span>
                </a>
            </li>
        </ul>
        <!-- 侧边栏折叠按钮 -->
        <div class="sidebar-footer">
            <button id="sidebar-toggle" class="btn">
                <i class="fas fa-chevron-left"></i>
            </button>
        </div>
    </nav>

    <!-- 主内容区 -->
    <main class="main-content">
        <!-- 页面标题 -->
        <div class="page-header">
            <h1 class="page-title">{% block page_title %}小红书数据管理{% endblock %}</h1>
            <!-- <div class="d-flex justify-content-between align-items-center">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="/">首页</a></li>
                        {% block breadcrumb %}{% endblock %}
                    </ol>
                </nav>
                <div class="page-actions">
                    {% block page_actions %}{% endblock %}
                </div>
            </div> -->
        </div>

        <!-- 消息提示 -->
        <div class="toast-container">
            {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
            {% for category, message in messages %}
            <div class="toast show" role="alert" aria-live="assertive" aria-atomic="true" data-bs-autohide="true" data-bs-delay="5000">
                <div class="toast-header">
                    <span class="me-auto text-{{ category }}">
                        {% if category == 'success' %}
                        <i class="fas fa-check-circle"></i>
                        {% elif category == 'danger' %}
                        <i class="fas fa-exclamation-circle"></i>
                        {% elif category == 'warning' %}
                        <i class="fas fa-exclamation-triangle"></i>
                        {% else %}
                        <i class="fas fa-info-circle"></i>
                        {% endif %}
                        提示信息
                    </span>
                    <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
                </div>
                <div class="toast-body">
                    {{ message }}
                </div>
            </div>
            {% endfor %}
            {% endif %}
            {% endwith %}
        </div>

        <!-- 内容区域 -->
        <div class="content-wrapper">
            {% block content %}{% endblock %}
        </div>
    </main>

    <!-- 页脚 -->
    <footer class="text-center py-3">
        <p class="mb-0">© 2025 JAVA外卖源权利所有</p>
    </footer>

    <!-- JavaScript 库 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 隐藏加载动画
            setTimeout(function() {
                document.getElementById('page-loader').style.display = 'none';
            }, 800);

            // 自动关闭消息提示
            setTimeout(function(){
                $('.toast').toast('hide');
            }, 5000);
            
            // 移动端侧边栏切换
            document.getElementById('mobile-toggle').addEventListener('click', function() {
                document.querySelector('.sidebar').classList.toggle('show');
            });
            
            // 侧边栏折叠功能
            document.getElementById('sidebar-toggle').addEventListener('click', function() {
                document.body.classList.toggle('sidebar-collapsed');
                
                if (document.body.classList.contains('sidebar-collapsed')) {
                    this.setAttribute('title', '展开侧边栏');
                } else {
                    this.setAttribute('title', '折叠侧边栏');
                }
                
                // 保存用户偏好
                localStorage.setItem('sidebar_collapsed', document.body.classList.contains('sidebar-collapsed'));
                
                // 通知ECharts图表重新调整大小
                setTimeout(function() {
                    if (typeof echarts !== 'undefined') {
                        const charts = document.querySelectorAll('[id$="Chart"]');
                        charts.forEach(chart => {
                            const instance = echarts.getInstanceByDom(chart);
                            if (instance) {
                                instance.resize();
                            }
                        });
                    }
                }, 300);
            });
            
            // 加载页面时恢复用户偏好
            if (localStorage.getItem('sidebar_collapsed') === 'true') {
                document.body.classList.add('sidebar-collapsed');
            }
        });
    </script>
    {% block scripts %}{% endblock %}
</body>
</html> 